<?php
namespace app\admin\controller;
use app\common\controller\TyCheck;
use app\admin\logic\BaseLogic;
use think\Controller;

/**
 * 基础控制器
 * Created by PhpStorm.
 * User: tyll
 * Date: 2019/09/16
 * Time: 15:40
 */
class Base extends Controller {

    use TyCheck;

    public function __construct(){
        parent::__construct();
        $this->b_logic = new BaseLogic();
        $this->b_logic->write_ao();
    }

    /**
     * 获取社区巡店联动
     * @return \think\response\Json
     */
    public function ajax_get_cp_linkage(){
        $params = input();
        $r = $this->check_admin_token($params);
        if($r['code'] != 1){
            return json($r);
        }

        $list = [];
        $maps = [];
        $b_list = model('branch')->get_list($maps,'id,name');
        foreach($b_list as $k_1 => $v_1){
            $list[$k_1]['value'] = $v_1['id'];
            $list[$k_1]['label'] = $v_1['name'];

            $b_children = [];
            $f_maps = [];
            $f_maps[] = ['branchid','=',$v_1['id']];
            $f_list = model('floor')->get_list($f_maps,'id,name');
            foreach($f_list as $k_2 => $v_2){
                $b_children[$k_2]['value'] = $v_2['id'];
                $b_children[$k_2]['label'] = $v_2['name'];

                $f_children = [];
                $f_maps = [];
                $f_maps[] = ['floorid','=',$v_2['id']];
                $r_list = model('region')->get_list($f_maps,'id,name');
                foreach($r_list as $k_3 => $v_3){
                    $f_children[$k_3]['value'] = $v_3['id'];
                    $f_children[$k_3]['label'] = $v_3['name'];
                }
                $b_children[$k_2]['children'] = $f_children;
            }
            $list[$k_1]['children'] = $b_children;
        }

        $data['list'] = $list;
        return json($this->b_logic->get_response(1,'OK',$data));
    }
}